var React = require('react');

var Bheader = require('../widget/Bheader');
var Icon = require('../components/Icon');
var ajax = require('../tools/ajax');

module.exports = React.createClass({
    getInitialState: function () {
        return {
            theme:"Default"
        }
    },
    myScroll:"",

    componentDidMount: function () {
        layer.open({type: 2});
        setTimeout(this.iscroll,2400);
        setTimeout(function(){
            layer.closeAll('loading')
        }, 2500);
    },
    /**iScroll插件*/
    iscroll(){
        var p =this;
        p.myScroll = new IScroll("#renwuInfoWrapper",{
            // 默认iscroll会拦截元素的默认事件处理函数，我们需要响应onClick，因此要配置
            preventDefault: false,
            // 禁止缩放
            zoom: false,
            // 支持鼠标事件，因为我开发是PC鼠标模拟的
            mouseWheel: true,
            // 滚动事件的探测灵敏度，1-3，越高越灵敏，兼容性越好，性能越差
            probeType: 3,
            // 拖拽超过上下界后出现弹射动画效果，用于实现下拉/上拉刷新
            bounce: true,
            // 展示滚动条
            scrollbars: false
        });
        p.myScroll.refresh();
        //var preHandler = function(e){e.preventDefault()};
        //document.addEventListener('touchmove', preHandler, false);
        //setTimeout(function(){
        //    document.removeEventListener('touchmove', preHandler, false);
        //},2000);
    },
    buy(){
        location.href = "#goodDetail";
        localStorage.price ="";
        localStorage.setItem("back","#renwuInfo");
    },
    render: function () {
        var p = this;
        var renwuInfo = localStorage.getItem("renwuInfo");
        if(renwuInfo) {
            var list = renwuInfo.split(",").map(function(obj){
                return(
                    <img key={obj} src={obj} alt=""/>
                )
            });
        }
        return (
            <div className="main"  id="main">
                <Bheader theme={this.state.theme} title="一人一物"  hact="#renwu"></Bheader>
                <div id="renwuInfoWrapper" className="container-t noFooter">
                    <div style={{minHeight:"31.16rem"}}>
                        {list}
                    </div>
                </div>
                <div onClick={p.buy} className="buyThing">
                    <img src="http://115.29.198.39:8080/upload/goods_person/221721378231637398.png" />
                </div>
            </div>
        )
    }
});
